package com.gulimall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gulimall.product.entity.AttrGroupWithAttrVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gulimall.common.utils.PageUtils;

import com.gulimall.product.dao.AttrGroupDao;
import com.gulimall.product.entity.AttrGroupEntity;
import com.gulimall.product.service.AttrGroupService;

import java.util.List;


/**
 * @author ht
 */
@Service("attrGroupService")
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEntity> implements AttrGroupService {
    @Override
    public IPage<AttrGroupEntity> queryPage(Page<AttrGroupEntity> page,AttrGroupEntity attrGroup,String key) {
        Long catelogId = attrGroup.getCatelogId();
        LambdaQueryWrapper<AttrGroupEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (catelogId != null) {
            lambdaQueryWrapper.eq(AttrGroupEntity::getCatelogId, catelogId);
        }
        if (StringUtils.isNotEmpty(key)) {
            lambdaQueryWrapper.like(AttrGroupEntity::getAttrGroupName, key)
                    .or().like(AttrGroupEntity::getSort, key)
                    .or().like(AttrGroupEntity::getDescript, key);
        }
        return baseMapper.selectPage(page, lambdaQueryWrapper);
    }

    @Override
    public IPage<AttrGroupEntity> queryAllDataPage(Page<AttrGroupEntity> page,AttrGroupEntity attrGroup, String key) {
        LambdaQueryWrapper<AttrGroupEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(key)) {
            lambdaQueryWrapper.like(AttrGroupEntity::getAttrGroupName, key)
                    .or().like(AttrGroupEntity::getSort, key)
                    .or().like(AttrGroupEntity::getDescript, key);
        }
        return baseMapper.selectPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<AttrGroupWithAttrVo> getAttrGroupWithAttrs(Long catId){
        return baseMapper.getAttrGroupWithAttrs(catId);
    }
}